package cn.iocoder.yudao.module.system.controller.admin.gugu;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.gugu.vo.CollegeRecommendItemVO;
import cn.iocoder.yudao.module.system.controller.admin.gugu.vo.CollegeRecommendReqVO;
import cn.iocoder.yudao.module.system.controller.admin.gugu.vo.CollegeRecommendRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 智能推荐大学简化控制器（用于测试）
 *
 * @author 芋道源码
 */
@Tag(name = "管理后台 - 智能推荐大学简化版")
@RestController
@RequestMapping("/system/college-recommendation-simple")
@Validated
@Slf4j
public class CollegeRecommendationSimpleController {

    @PostMapping("/recommend")
    @Operation(summary = "智能推荐大学（简化版）")
    public CommonResult<CollegeRecommendRespVO> recommendColleges(@Valid @RequestBody CollegeRecommendReqVO reqVO) {
        log.info("智能推荐大学请求（简化版）：{}", reqVO);
        
        try {
            // 创建模拟数据
            CollegeRecommendRespVO respVO = createMockResponse(reqVO);
            return success(respVO);
        } catch (Exception e) {
            log.error("智能推荐大学失败", e);
            return CommonResult.error(500, "推荐服务异常：" + e.getMessage());
        }
    }

    /**
     * 创建模拟响应数据
     */
    private CollegeRecommendRespVO createMockResponse(CollegeRecommendReqVO reqVO) {
        CollegeRecommendRespVO respVO = new CollegeRecommendRespVO();
        
        // 创建模拟推荐院校列表
        List<CollegeRecommendItemVO> list = new ArrayList<>();
        
        // 冲刺院校
        CollegeRecommendItemVO chongItem = new CollegeRecommendItemVO();
        chongItem.setUniversityName("南京大学");
        chongItem.setRecruitCode("1101");
        chongItem.setProvince("江苏");
        chongItem.setCity("南京");
        chongItem.setPropertyName("公办");
        chongItem.setCategoryName("综合");
        chongItem.setType("CHONG");
        chongItem.setEnrollProbability(25);
        chongItem.setPlanNum(45);
        chongItem.setMinScore(595);
        chongItem.setMinRanks(12000);
        chongItem.setMajorName("计算机科学与技术");
        chongItem.setClaim("物理+化学");
        chongItem.setBatch("本科批");
        chongItem.setTags(Arrays.asList("985", "211", "双一流"));
        chongItem.setRecommendationReason("985工程院校，该专业就业前景良好，有一定冲刺可能性");
        chongItem.setYear(reqVO.getYear());
        chongItem.setRanking(8);
        chongItem.setUniversityId("uuid-001");
        chongItem.setZsgkId(1001L);
        chongItem.setOrcId(1001001L);
        chongItem.setScoreSection(true);
        chongItem.setIndexVip(false);
        chongItem.setLevel("本科");
        chongItem.setOriginUniversityName("南京大学");
        list.add(chongItem);
        
        // 稳妥院校
        CollegeRecommendItemVO wentuoItem = new CollegeRecommendItemVO();
        wentuoItem.setUniversityName("南京理工大学");
        wentuoItem.setRecruitCode("1102");
        wentuoItem.setProvince("江苏");
        wentuoItem.setCity("南京");
        wentuoItem.setPropertyName("公办");
        wentuoItem.setCategoryName("理工");
        wentuoItem.setType("WENTUO");
        wentuoItem.setEnrollProbability(75);
        wentuoItem.setPlanNum(80);
        wentuoItem.setMinScore(575);
        wentuoItem.setMinRanks(18000);
        wentuoItem.setMajorName("软件工程");
        wentuoItem.setClaim("物理");
        wentuoItem.setBatch("本科批");
        wentuoItem.setTags(Arrays.asList("211", "双一流"));
        wentuoItem.setRecommendationReason("211工程院校，该专业就业前景良好，录取概率较高");
        wentuoItem.setYear(reqVO.getYear());
        wentuoItem.setRanking(45);
        wentuoItem.setUniversityId("uuid-002");
        wentuoItem.setZsgkId(1002L);
        wentuoItem.setOrcId(1002001L);
        wentuoItem.setScoreSection(true);
        wentuoItem.setIndexVip(false);
        wentuoItem.setLevel("本科");
        wentuoItem.setOriginUniversityName("南京理工大学");
        list.add(wentuoItem);
        
        // 保底院校
        CollegeRecommendItemVO baodiItem = new CollegeRecommendItemVO();
        baodiItem.setUniversityName("南京邮电大学");
        baodiItem.setRecruitCode("1103");
        baodiItem.setProvince("江苏");
        baodiItem.setCity("南京");
        baodiItem.setPropertyName("公办");
        baodiItem.setCategoryName("理工");
        baodiItem.setType("BAODI");
        baodiItem.setEnrollProbability(95);
        baodiItem.setPlanNum(120);
        baodiItem.setMinScore(555);
        baodiItem.setMinRanks(25000);
        baodiItem.setMajorName("通信工程");
        baodiItem.setClaim("物理");
        baodiItem.setBatch("本科批");
        baodiItem.setTags(Arrays.asList("双一流学科"));
        baodiItem.setRecommendationReason("通信专业全国知名，录取把握很大");
        baodiItem.setYear(reqVO.getYear());
        baodiItem.setRanking(78);
        baodiItem.setUniversityId("uuid-003");
        baodiItem.setZsgkId(1003L);
        baodiItem.setOrcId(1003001L);
        baodiItem.setScoreSection(true);
        baodiItem.setIndexVip(false);
        baodiItem.setLevel("本科");
        baodiItem.setOriginUniversityName("南京邮电大学");
        list.add(baodiItem);
        
        // 设置分页信息
        respVO.setTotal(3L);
        respVO.setList(list);
        respVO.setPageNum(reqVO.getPageNum());
        respVO.setPageSize(reqVO.getPageSize());
        respVO.setSize(3);
        respVO.setStartRow(1);
        respVO.setEndRow(3);
        respVO.setPages(1);
        respVO.setPrePage(0);
        respVO.setNextPage(0);
        respVO.setIsFirstPage(true);
        respVO.setIsLastPage(true);
        respVO.setHasPreviousPage(false);
        respVO.setHasNextPage(false);
        respVO.setNavigatePages(8);
        respVO.setNavigatepageNums(Arrays.asList(1));
        respVO.setNavigateFirstPage(1);
        respVO.setNavigateLastPage(1);
        
        // 设置汇总信息
        CollegeRecommendRespVO.SummaryVO summary = new CollegeRecommendRespVO.SummaryVO();
        summary.setUserScore(reqVO.getScore());
        summary.setUserRank(reqVO.getRanks() != null ? reqVO.getRanks() : 15000);
        summary.setProvince(reqVO.getProvince());
        summary.setExamType(reqVO.getClassify() + "类");
        summary.setSubjectCombination(reqVO.getSubjects().replace(",", "+"));
        summary.setChongCount(1);
        summary.setWentuoCount(1);
        summary.setBaodiCount(1);
        summary.setAnalysisText(String.format("基于您的分数%d分，位次%d名，为您推荐3所院校", 
                reqVO.getScore(), summary.getUserRank()));
        respVO.setSummary(summary);
        
        return respVO;
    }

    @GetMapping("/health")
    @Operation(summary = "健康检查")
    public CommonResult<String> health() {
        return success("智能推荐大学接口运行正常");
    }
}
